package com.xayy.scheduled.controller;


import cn.kawins.base.result.ResultBody;
import com.github.pagehelper.PageInfo;
import com.xayy.mgt.service.NodeInfoService;
import com.xayy.scheduled.convert.AssessTaskInfoConvert;
import com.xayy.scheduled.model.AssessTaskInfo;
import com.xayy.scheduled.model.dto.AssessTaskInfoDto;
import com.xayy.scheduled.model.vo.AssessTaskInfoVo;
import com.xayy.scheduled.model.vo.AssessTaskInfoVo2;
import com.xayy.scheduled.service.AssessTaskInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
*  controller
*
* @ClassName: AssessTaskInfoController
* @Description: 控制层访问接口
* @author liuyuan
* @date 2025-06-24
*/
@Api(tags="设备参数数据模拟接口")
@RestController
@AllArgsConstructor
@RequestMapping("/dataMock")
public class DataMockController {

    @PostMapping({"/searchByTime"})
    @ApiOperation(value = "按时间段模拟数据")
    public ResultBody searchByTime(@RequestBody AssessTaskInfoDto query){
        // 将 Date 转为 LocalDateTime（使用系统默认时区）
        LocalDateTime start = query.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        LocalDateTime end = query.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

        List<Integer> values = new ArrayList<>();
        Random random = new Random();

        long hours = ChronoUnit.HOURS.between(start, end);
        for (int i = 0; i <= hours; i++) {
            int value = 40 + random.nextInt(61); // 0~60 + 40 = 40~100
            values.add(value);
        }

        return ResultBody.success(values);
    }

}